/*
 * @Author: xushuhao
 * @Email: xshmouse@163.com
 * @Date: 2020-04-19 21:50:59
 * @Last Modified by: xushuhao
 * @Last Modified time: 2020-07-28 08:40:01
 * @Description: DEMO页面，其它业务页面可以参照此页面模板进行。
 */

import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_code_framework/base/base_widget.dart';
import 'package:flutter_code_framework/route/route_transition.dart';
import 'package:flutter_code_framework/utils/global.dart';
import 'package:flutter_code_framework/widgets/x_video_player.dart';

import 'demo_player.dart';
import 'demo_player_trans.dart';

class DemoPage extends BaseWidget {
  final Map args;

  DemoPage({this.args});

  @override
  BaseWidgetState<BaseWidget> getState() {
    return _DemoPageState();
  }
}

class _DemoPageState extends BaseWidgetState<DemoPage> {
  Map args;
  String videoPath = '';
  String pothoPath = '';
  StreamSubscription _colorSubscription;
  StreamSubscription _pothoColorSubscription;

  var temp = [
    PlayerInputInstance(title: '多边形的外角和', list: [
      VideoType(
          name: '标清',
          url:
              'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/18/4f1a8237-d0ca-407a-bf18-277694f15751/video/746cd2471b0245ac8db377a306d49c3a.mp4'),
      VideoType(
          name: '高准',
          url:
              'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/18/4f1a8237-d0ca-407a-bf18-277694f15751/video/746cd2471b0245ac8db377a306d49c3a.mp4'),
      VideoType(
          name: '超清',
          url:
              'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/18/4f1a8237-d0ca-407a-bf18-277694f15751/video/3ae12334bf2c4e1d9aa8581fb2e92310.mp4')
    ]),
    PlayerInputInstance(title: '三角形的角平分线', list: [
      VideoType(
          name: '高清',
          url:
              'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/882b010f-74fc-413f-a54b-1a9e23470883/video/097e56983db64672b25ac83179fa409d.mp4')
    ]),
    PlayerInputInstance(title: '三角形的高', list: [
      VideoType(
          name: '标清',
          url:
              'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/bc5468e2-19ac-4e6e-9cee-934504a94527/video/1d5be1643c7a4995ba0dc10036c922d4.mp4'),
      VideoType(
          name: '高准',
          url:
              'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/bc5468e2-19ac-4e6e-9cee-934504a94527/video/39948fd01c8442d59311369cf070e1f6.mp4'),
      VideoType(
          name: '超清',
          url:
              'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/bc5468e2-19ac-4e6e-9cee-934504a94527/video/1d5be1643c7a4995ba0dc10036c922d4.mp4')
    ]),
    PlayerInputInstance(title: '多边形的内角和', list: [
      VideoType(
          name: '高清',
          url:
              'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/882b010f-74fc-413f-a54b-1a9e23470883/video/097e56983db64672b25ac83179fa409d.mp4')
    ]),
  ];

  @override
  Widget buildWidget(BuildContext context) {
    int t = 0;
    return ListView.builder(
        itemCount: 1,
        itemBuilder: (BuildContext context, int index) {
          return Column(
            children: <Widget>[
              GestureDetector(
                child: Text('两次双击才行'),
                onDoubleTap: () {
                  t = t + 2;
                  if (t == 4) {
                    showNormalToast('我出来了！！！！');
                    t = 0;
                  }
                },
              ),
              RaisedButton(
                child: Text(
                  "Toast 提示 DEMO页面！！！！\n参数：args：" + args.toString(),
                ),
                onPressed: () {
                  Navigator.pushNamed(context, '/demo_flutter_toast');
                },
              ),
              RaisedButton(
                child: Text(
                  "确定取消弹窗",
                ),
                onPressed: () {
                  G.showToastDialog(context,
                      "美国生物技术企业莫德纳公司和辉瑞制药有限公司各自的新冠病毒疫苗三期临床试验27日同时启动，受试者各约3万人。两项试验有望为疫苗今年底前通过监管审批继而广泛使用铺平道路美国生物技术企业莫德纳公司和辉瑞制药有限公司各自的新冠病毒疫苗三期临床试验27日同时启动，受试者各约3万人。两项试验有望为疫苗今年底前通过监管审批继而广泛使用铺平道路美国生物技术企业莫德纳公司和辉瑞制药有限公司各自的新冠病毒疫苗三期临床试验27日同时启动，受试者各约3万人。两项试验有望为疫苗今年底前通过监管审批继而广泛使用铺平道路美国生物技术企业莫德纳公司和辉瑞制药有限公司各自的新冠病毒疫苗三期临床试验27日同时启动，受试者各约3万人。两项试验有望为疫苗今年底前通过监管审批继而广泛使用铺平道路",
                      title: "提示", callBack: clickDialogOk);
                },
              ),
              Text('自定义字体 PingFang ：',
                  style: TextStyle(
                      fontFamily: 'pf', color: Theme.of(context).accentColor)),
              Text('自定义icon 引用demo：',
                  style: TextStyle(color: Theme.of(context).accentColor)),
              Icon(
                IconData(0xe602, fontFamily: 'myTestIcons'),
                size: 50,
                color: Colors.pink,
              ),
              Text('当前os 是否暗黑模式：' + isDark.toString()),
              RaisedButton(
                child: Text(
                  "我是SF Symbols List页面！！！！",
                ),
                onPressed: () {
                  Navigator.pushNamed(context, '/demo_sf_symbols');
                },
              ),
              RaisedButton(
                child: Text(
                  "我是主题管理页面demo！！！！",
                ),
                onPressed: () {
                  Navigator.pushNamed(context, '/demo_theme');
                },
              ),
              RaisedButton(
                child: Text(
                  "自定义播放器 - 全屏",
                ),
                onPressed: () {
                  if (videoPath != '') {
                    RouteTransition(DemoPlayer(path: [
                      PlayerInputInstance(
                          title: '本地摄像头录制视频',
                          list: [VideoType(name: '高清', url: videoPath)]),
                    ], sourceType: 'file'))
                        .pushTransRoute(context);
                  } else {
                    RouteTransition(
                            DemoPlayer(path: temp, sourceType: 'network'))
                        .pushTransRoute(context);
                    // Navigator.pushNamed(context, '/demo_player');
                  }
                },
              ),
              RaisedButton(
                child: Text(
                  "自定义播放器 - 小屏 支持全屏切换",
                ),
                onPressed: () {
                  RouteTransition(DemoPlayerTrans()).pushTransRoute(context);
                  // Navigator.pushNamed(context, '/demo_player_trans');
                },
              ),
              RaisedButton(
                child: Text(
                  "基类公共提示页面！！！！",
                ),
                onPressed: () {
                  Navigator.pushNamed(context, '/demo_tabbar');
                },
              ),
              RaisedButton(
                child: Text(
                  "Picker具体使用见基类公共提示页面",
                ),
                onPressed: () {
                  Navigator.pushNamed(context, '/cupertino_picker');
                },
              ),
              RaisedButton(
                child: Text(
                  "demoimage",
                ),
                onPressed: () {
                  Navigator.pushNamed(context, '/demo_image');
                },
              ),
               RaisedButton(
                child: Text(
                  "IOS 视频录制",
                ),
                onPressed: () {
                  Navigator.pushNamed(context, '/demo_iosvideo');
                },
              ),

               RaisedButton(
                child: Text(
                  "参数配置 视频录制",
                ),
                onPressed: () {
                  Navigator.pushNamed(context, '/demo_video');
                },
              ),

            ],
          );
        });
  }

  Function clickDialogOk() {
    print("点击了确认按钮");
  }

  @override
  void initState() {
    super.initState();
    setState(() {
      args = widget.args;
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _colorSubscription.cancel();
  }

  @override
  void onCreate() {
    // log("onCreate");
    setAppTopNavBarVisible(true);
    // setLoadingWidgetVisible(true);
    setTopNavTitle("Demo");
  }

  @override
  void onPause() {
    // log('onPause');
  }

  @override
  void onResume() {
    // log("onResume");
  }
}
